<?php

namespace App\Http\Controllers\Front;

use App\Http\Controllers\Controller;
use App\Model\Admin\Product;
use App\Model\Front\Category;
use Illuminate\Http\Request;

class CategoryController extends Controller
{
    public function index(Request $request)
    {
        if ($request->ajax()) {
            // dd($request->input());
            $products = Product::where('pro_prices', '>=', $request->start)
                     ->where('pro_prices', '<=', $request->end)
                     ->orderBy('pro_prices', 'desc')
                     ->paginate(10);
            return view('front.product.rproduct', compact('products'));
        }
        $products = Product::paginate(10);

        // $wishlist = $product->wishlist()->get();
        return view('front.categori', compact('products'))->withKeyword('')->withCatename('所有商品');
    }

    public function show(Category $category)
    {
        $products = $category->products()->paginate(10);
        
        return view('front.categori', compact('products'))->withKeyword('')->withCatename($category->name);
    }
}
